﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MacrophageCell : MonoBehaviour {
    public float max_kill_Num;
    private float kill_Num = 0;
    public float max_Repair_Num;
    private float repair_Num = 0;
    private Cell m_Cell;

    
    public GameObject destroyEffect;
    // Use this for initialization
    private void Awake()
    {


        m_Cell = GetComponent<Cell>();
    }


    // Update is called once per frame
    void Update () {
        GameObject target = m_Cell.UpdateTarget(CombinVirus);;
        if (target != null)
        {
            m_Cell.FollowTarget(target);
        }
        else
        {
            m_Cell.Wander();
        }


    }
    //public GameObject FollowTarget()
    //{
    //    GameObject target = null;
    //    RaycastHit2D[] rh = Physics2D.CircleCastAll(transform.position, DetectRange, transform.up, 0);
    //    float Dmin = 9999;
    //    if (rh != null)
    //    {
    //        foreach (RaycastHit2D hit in rh)
    //        {
    //            if (hit.collider.tag == TargetTag)
    //            {
    //                Vector3 dir = hit.collider.gameObject.transform.position - transform.position;

    //                if (Dmin >= dir.magnitude)
    //                {
    //                    Dmin = dir.magnitude;

    //                    target = hit.collider.gameObject;
    //                    if (dir.magnitude < AttackRange)
    //                    {
    //                        if (this.gameObject.activeSelf == true)
    //                        {
    //                            // Debug.Log(this.gameObject.transform.position);
    //                            process(target);
    //                        }

    //                    }
    //                }
    //            }
    //        }
    //        return;
    //}
    public void CombinVirus(GameObject target)
    {
        if(destroyEffect != null) {
            GameObject obj = Instantiate(destroyEffect, target.transform.position, Quaternion.identity);
            Destroy(obj, 0.5f);
        }
        Destroy(target);
        kill_Num += 1;
        if(kill_Num== max_kill_Num)
        {
             Destroy(this.gameObject);
        }
        
        GameUIController.Instance.gameObject.GetComponent<AudioSource>().Play();
        
        

    }
    public void InfectedCell(GameObject target)
    {


    }
}
